package com.roger.cmdkit.demo;

import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;


public class Gui extends JFrame {
    private TextField tf1;
    private TextField tf2;
    private TextField tf3 ;
    private void launch()
    {
        JFrame jf = new JFrame();
        jf.setBounds(200,200,200,150);
        jf.setTitle("test");
        ImageIcon icon = new ImageIcon("C:\\Users\\admin\\Desktop\\11.png");
        jf.setIconImage(icon.getImage());
        JLabel jla= new JLabel(icon);
        jf.add(jla);
        //jf.setSize(400, 500);
        tf1 = new TextField(15);
        tf2 = new TextField(15);
        tf3 = new TextField(15);
        Label lb = new Label("  + ");
        Button bn = new Button("=");
        jf.setLayout(new FlowLayout(5,5,FlowLayout.CENTER));
        jf.add(tf1);
        jf.add(lb);
        jf.add(tf2);
        jf.add(bn);
        bn.addActionListener(new MyClick(this));
        jf.add(tf3);
        jf.setVisible(true);
        jf.addWindowListener(
                new WindowAdapter() {
                    @Override
                    public void windowClosing(WindowEvent e)
                    {
                        System.exit(-1);
                    }
                }
        );
       jf.pack();
    }


    class MyClick implements ActionListener {
        Gui tf;

        MyClick(Gui tf) {
            this.tf = tf;
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            int d = Integer.valueOf(tf.tf1.getText()) + Integer.valueOf(tf.tf2.getText());
            tf.tf3.setText(String.valueOf(d));
        }
    }

    public static void main(String[] args)
    {
        new Gui().launch();
    }




}

